package com.kuaikan.cnbeta.activity;

import java.io.Serializable;
import java.util.List;

import com.bsi.app.BaseActivity;
import com.bsi.app.widget.ToastUtil;
import com.kuaikan.cnbeta.R;
import com.kuaikan.cnbeta.pojo.News;
import com.kuaikan.cnbeta.util.Const;
import com.kuaikan.cnbeta.util.Msg;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;

public class LoadingActivity extends BaseActivity {
	List<News> list;
	public static final String NEWS_TITLE_LIST = "newsTitleList";

	@Override
	public void setCurrentContentView() {
		setContentView(R.layout.act_loading);
	}

	void initData() {
		new Thread() {
			public void run() {
				try {
					list = srvcFactory.getNewsSrvc().getNewsTitles(
							Const.CN_BETA_URL);
					handler.sendEmptyMessage(Msg.DONE);
				} catch (Exception e) {
					handler.sendEmptyMessage(Msg.TIMEOUT);
					e.printStackTrace();
				}
			};
		}.start();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		initData();
	}

	Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			if (msg.what == Msg.TIMEOUT) {
				ToastUtil.showTimeoutToast(LoadingActivity.this);
			} else if (msg.what == Msg.DONE) {
			}
			new Handler().postDelayed(new Runnable() {
				public void run() {
					Intent intentToMain = new Intent(LoadingActivity.this,
							HomeActivity.class);
					intentToMain.putExtra(NEWS_TITLE_LIST, (Serializable) list);
					LoadingActivity.this.startActivity(intentToMain);
					LoadingActivity.this.finish();
				}
			}, 1000);
		};
	};


}
